package com.gxa.controller;

import com.gxa.common.LayR;
import com.gxa.common.R;
import com.gxa.param.TableParam;
import com.gxa.pojo.Empl;
import com.gxa.pojo.Serve;
import com.gxa.pojo.sale.SaleMan;
import com.gxa.pojo.sale.SalePlan;
import com.gxa.service.SaleService;
import com.gxa.service.ServeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/sale")
public class SaleController {

    @Autowired(required = false)
    private SaleService saleService;


    /**
     * 销售计划列表页面
     * @return
     */
    @GetMapping("/plan/page")
    public String list(){
        return "sale/sale-plan";
    }

    /**
     * 销售计划数据
     * @return
     */
    @PostMapping("/list/data")
    @ResponseBody
    public LayR listData(TableParam param){
        return saleService.list(param);
    }

    /**
     * 销售计划添加数据
     * @return
     */

    @PostMapping("/deleteOne")
    @ResponseBody
    public R delete(Integer id){

        return saleService.deleteOne(id);

    }

    @PostMapping("/delete")
    @ResponseBody
    public R delete(@RequestParam("ids[]") String[] ids){

        return saleService.deleteAll(ids);
    }


    @GetMapping("/add/page")

    public String addPage(){
        return "sale/plan-add";
    }



    @PostMapping("/add/do")
    @ResponseBody
    public R add(SalePlan salePlan){
        return saleService.add(salePlan);
    }

    @GetMapping("/edit/page")
    public String editPage(Integer id, Model model){
        model.addAttribute("saleId", id);
        return "sale/plan-edit";
    }

    /**
     * 详情
     * @param id
     * @return
     */
    @PostMapping("/detail")
    @ResponseBody
    public R detail(Integer id){
        return saleService.detail(id);
    }

    @PostMapping("/edit/do")
    @ResponseBody
    public R edit(SalePlan salePlan){
        return saleService.edit(salePlan);
    }




    /**
     * 联系人列表页面
     * @return
     */

    /**
     * 销售计划列表页面
     * @return
     */
    @GetMapping("/contact/page")
    public String ContactList(){ return "sale/contact-list";
    }

    @PostMapping("/contact/data")
    @ResponseBody
    public LayR ContactData(TableParam param){
        return saleService.contactList(param);
    }

    @GetMapping("/contact/add/page")
    public String addContact(){ return "sale/contact-add";
    }
    @PostMapping("/contact/add/do")
    @ResponseBody
    public R addContact(SaleMan saleMan){
        return saleService.addContact(saleMan);
    }

    @PostMapping("/contact/delete")
    @ResponseBody
    public R contactDelete(@RequestParam("ids[]") String[] ids){

        return saleService.ContactDeleteAll(ids);
    }

    @GetMapping("/contact/editPage")
    public String ContactEdit(Integer id, Model model){
        model.addAttribute("id", id);
        return "/sale/contact-edit";
    }

    @PostMapping("/contact/detail")
    @ResponseBody
    public R contactDetail(Integer id){
        return saleService.contactDetail(id);
    }

    @PostMapping("/contact/update")
    @ResponseBody
    public R contactUpdate(SaleMan saleMan){
        return saleService.contactUpdate(saleMan);
    }
}
